package com.mls.guardian.remoting.client;


import com.mls.guardian.protocol.CodeType;
import com.mls.guardian.protocol.RemoteBody;
import com.mls.guardian.protocol.RemoteCommand;
import com.mls.guardian.protocol.body.AppHeatBeatBody;
import com.mls.guardian.remoting.client.Client;
import com.mls.guardian.remoting.netty.RemotInvoke;
import com.mls.guardian.remoting.netty.RemoteTools;

/**
 * Created by jl on 15/9/9.
 */
public class RemoteInvoke implements RemotInvoke {
    private Client client;

    public RemoteInvoke(Client client) throws Exception {
        this.client = client;
    }




    @Override
    public RemoteBody ping() throws Exception {
        AppHeatBeatBody remoteBody = new AppHeatBeatBody();
        remoteBody.setAppName("guard");

        RemoteCommand remoteCommand = RemoteTools.getRequestRemoteCmd(CodeType.SLAVE_HEAR_BEAT, remoteBody);
        remoteCommand.setClientId("slave");
        RemoteCommand reponse = client.sendMessageSync(remoteCommand, 5000);

        return reponse.getRemoteBody();
    }

    @Override
    public void reconnect() throws Exception {
        client.reconnect();
    }

    @Override
    public boolean keepAaliveIsActive() {
        return client.keepAaliveIsActive();
    }

}
